home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2c.lha / p4-1.2c / misc / temp1.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  3KB  |  133 lines

  1. #define ALOG_TRACE
  2. #include "p4.h"
  3. #include "sr_user.h"
  4.  
  5. #define MAX_MESSAGE_SIZE 1500000
  6. char msg[MAX_MESSAGE_SIZE];
  7.  
  8. #define SENDING 99
  9.  
  10. int main(argc,argv)
  11. int argc;
  12. char **argv;
  13. {
  14.  
  15.     p4_initenv(&argc,argv);
  16.  
  17.     ALOG_ENABLE;
  18.     ALOG_MASTER(p4_get_my_id(),ALOG_TRUNCATE);
  19.     ALOG_DEFINE(SENDING,"Sending","");
  20.  
  21.     if (p4_get_my_id() == 0)
  22.     {
  23.         p4_create_procgroup();
  24.     master();
  25.     }
  26.     else
  27.     {
  28.         slave();
  29.     }
  30.   
  31.     ALOG_OUTPUT;
  32.     p4_wait_for_end();
  33. }
  34.  
  35.     
  36. master()
  37. {
  38.     int nslaves;
  39.     int type, size, id, from;
  40.     int my_id;
  41.     char *incoming;
  42.     int done;
  43.     int msgsize, count;
  44.     int starttime, endtime;
  45.     p4_usc_time_t start_ustime, end_ustime;
  46.  
  47.     nslaves = p4_num_total_slaves();
  48.     printf("number of slaves = %d\n",nslaves);
  49.     my_id = p4_get_my_id();
  50.     
  51.     done = FALSE;
  52.     while (!done)
  53.     {
  54.     printf("message size: ");
  55.     scanf("%d",&msgsize);
  56.     if (msgsize > MAX_MESSAGE_SIZE)
  57.     {
  58.         printf("too big;  using %d\n",MAX_MESSAGE_SIZE);
  59.         msgsize = MAX_MESSAGE_SIZE;
  60.     }
  61.     printf("times around loop (or 0 for end): ");
  62.     scanf("%d",&count);
  63.     
  64.     if (count == 0)
  65.         done = TRUE;
  66.     else
  67.     {
  68.         starttime = p4_clock();
  69.         start_ustime = p4_ustimer();
  70.         while (count > 0)
  71.         {
  72.                 ALOG_LOG(p4_get_my_id(),SENDING,DATA,"");
  73.         p4_sendr(DATA, 1, msg, msgsize);
  74.         type = -1;
  75.         from = -1;
  76.         incoming = NULL;
  77.         p4_recv(&type, &from, &incoming, &size);
  78.         p4_msg_free(incoming);
  79.         count--;
  80.         }
  81.         end_ustime = p4_ustimer();
  82.         endtime = p4_clock();
  83.         printf("time %d milliseconds\n",endtime-starttime);
  84.         printf("time %d microseconds\n",end_ustime-start_ustime);
  85.     }
  86.     }
  87.  
  88.     ALOG_LOG(p4_get_my_id(),SENDING,END,"");
  89.     p4_sendr(END, 1, msg, 0);
  90.     type = -1;
  91.     from = -1;
  92.     incoming = NULL;
  93.     p4_recv(&type, &from, &incoming, &size);
  94.     p4_msg_free(incoming);
  95.     p4_wait_for_end();
  96.     printf("master exiting normally\n");
  97. }
  98.  
  99. slave()    
  100. {
  101.     int nslaves;
  102.     int done;
  103.     int type, from, size;
  104.     int next;
  105.     int my_id;
  106.     char *incoming;
  107.     
  108.     ALOG_SETUP(p4_get_my_id(),ALOG_TRUNCATE);
  109.     my_id = p4_get_my_id();
  110.     nslaves = p4_num_total_slaves();
  111.     
  112.     if (my_id == nslaves)
  113.         next = 0;
  114.     else
  115.     next = my_id + 1;
  116.     
  117.     done = FALSE;
  118.     while (!done)
  119.     {
  120.     type = -1;
  121.     from = -1;
  122.     incoming = NULL;
  123.     p4_recv(&type,&from, &incoming, &size);
  124.     if (type == END)
  125.         done = TRUE;
  126.     ALOG_LOG(p4_get_my_id(),SENDING,type,"");
  127.     p4_sendr(type, next, incoming, size);
  128.     p4_msg_free(incoming);
  129.     }
  130.     ALOG_OUTPUT;
  131. }
  132.  
  133.